package psd.scala.rules

import scala.collection.mutable

import org.eclipse.jdt.core.dom.Modifier

import psd.model.Bug
import psd.scala.FactDb

class NoAbstractMethodInterface (description: String) extends AbstractRule (description){

  def execute(db: FactDb): mutable.ArrayBuffer[Bug]= {
    
   	 val methodDefTList = db.methodDefTList
   	 val classDefTlist = db.classDefTList
   	 
   	 val result = new mutable.ArrayBuffer[Bug]
   	 	 for ( cd <- classDefTlist ) {
   	   	   if (cd.isInterface) {
   	   		   val absMethods = methodDefTList.filter(m => Modifier.isAbstract(m.modifier))
   	   				   				.filter(_.path == cd.path)
				//Cambiando logica de interface con metodos abstractos
   	   			//for (am <- absMethods) {
   	   			//Interface con metodos no abstractos
   	   			if (!cd.methodCount.equals(absMethods.length)){
	   				 val bug = new Bug
				     bug.set_lineNumber(cd.line.toInt)
				     bug.set_path(cd.path)
			    	 bug.set_ruleName(this.getClass().toString())
			    	 bug.set_description(this.description)
			    	 result+=bug
				 }
	   		}
	   		 
	   	 }
	   	 return result
	  }
}